﻿namespace FindLargeFolderDotnet8AOT
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("取得参数:");
            foreach (string arg in args)
            {
                Console.WriteLine(arg);
            }
            Console.WriteLine("___________");
            FindLargeFolder findLargeFolder = new FindLargeFolder();
            if (args.Length == 0)
            {
                Console.WriteLine("未指定文件夹参数");
                return;
            }
            if (!args.Contains("-D"))
            {
                Console.WriteLine("未指定文件夹参数");
                return;
            }
            var argsList = args.ToList();
            if (argsList.IndexOf("-D") + 1 >= argsList.Count)
            {
                Console.WriteLine("未指定文件夹参数");
                return;
            }
            var indexCount = 30;
            if (argsList.Contains("-T") && argsList.IndexOf("-T") + 1 < argsList.Count)
            {
                int.TryParse(argsList[argsList.IndexOf("-T") + 1], out indexCount);
            }
            var path = argsList[argsList.IndexOf("-D") + 1];
            Console.WriteLine("开始计算指定文件夹 " + path);
            var result = findLargeFolder.FindLargeFolders(path);
            for (int i = 0; i < indexCount; i++)
            {
                if (i < result.Count)
                {
                    System.Console.WriteLine(result[i].path + " 大小：" + findLargeFolder.presentSize(result[i].size) + " 文件夹深度：" + result[i].depth);
                }
            }
        }
    }
}
